<?php

	require("header.php");
	require("table_des_matieres.php");
	
?>
	<fieldset>
	<legend><?php echo $language[$_SESSION['lang']]["ManageYourProfile"]; ?></legend>
	<a href="editProfile.php"><?php echo $language[$_SESSION['lang']]["ManageYourProfile"]; ?></a><br />
	</fieldset>

	<fieldset>
		<legend><?php echo $language[$_SESSION['lang']]["Users"]; ?></legend>
		
		<form method="POST">
			<input type="text" value="<?php echo $language[$_SESSION['lang']]["Defaultlogin"]; ?>" name="user" />
			<input type="submit" value="<?php echo $language[$_SESSION['lang']]["Search"]; ?>"
		</form>
		
		<a href="administrateur.php?list=user list"><?php echo $language[$_SESSION['lang']]["SeeUserList"]; ?></a><br />
		<a href="administrateur.php?list=ban list"><?php echo $language[$_SESSION['lang']]["SeeBanList"]; ?></a>
	</fieldset>

<?php
	if (!empty($users))
	{
		if (isset($_GET["list"]))
		{
			echo "<fieldset><legend>".ucfirst($_GET["list"])."</legend>";
		}
		else
		{
			echo "<fieldset><legend>".$language[$_SESSION['lang']]["Search"]."</legend>";
		}
		
		if (isset($_GET["list"]))
		{
			if ($_GET["list"] == "user list")
			{
				$submitText = $language[$_SESSION['lang']]["BanUser"];
				$name = "ban";
			}
			else
			{
				$submitText = $language[$_SESSION['lang']]["UnBanUser"];
				$name = "unban";
			}
		}
		else if (isset($_POST["user"]))
		{
			if (isset($users[0]->valide))
			{
				if ($users[0]->valide)
				{
					$submitText = $language[$_SESSION['lang']]["BanUser"];
					$name = "ban";
				}
				else
				{
					$submitText = $language[$_SESSION['lang']]["UnBanUser"];
					$name = "unban";
				}
			}
		}
		
		foreach ($users as $user)
		{
			if (isset($user->nom))
			{
			
			$client = "";
			$int = "";
			$proprio = "";
			$admin = "";
			
			switch ($user->ref_categorie)
			{
				case "1":
					$client = ' selected = "selected"';
				break;
				case "2":
					$int = ' selected = "selected"';
				break;
				case "3":
					$proprio = ' selected = "selected"';
				break;
				case "4":
					$admin = ' selected = "selected"';
				break;
			}
			if ($user->ref_categorie == "1")
			{
				$client = " SELECTED";
				$int = "";
				$proprio = "";
				$admin = "";
			}
			
			
			echo '	<form method="POST" style="float:right;clear:right;margin:0;">
						<input type="hidden" name="user" value="'.$user->id.'" />
						<select name="droits">
							<option value="1"'.$client.'>'.$language[$_SESSION['lang']]["client"].'</option>
							<option value="2"'.$int.'>'.$language[$_SESSION['lang']]["middleman"].'</option>
							<option value="3"'.$proprio.'>'.$language[$_SESSION['lang']]["owner"].'</option>
							<option value="4"'.$admin.'>'.$language[$_SESSION['lang']]["admin"].'</option>
						</select>
						<input type="submit" name="changeRights" value="'.$language[$_SESSION['lang']]["ChangeRights"].'">
						<input type="submit" name="'.$name.'" value="'.$submitText.'">
						<input type="submit" name="delete" value="'.$language[$_SESSION['lang']]["DeleteUser"].'">				
					</form>';
			echo '<span style="float:left;">'.$user->login.'</span>';
			}
		}
		
		echo "</fieldset>";
	}
	
	require("footer.php");
	
?>
